package com.music.service.songs.beans;

import java.sql.Date;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import com.music.service.songs.constants.SongState;
import com.music.service.urls.beans.Url;

public class Song {
	private Long mSongId;
	private Long mOwnerId;
	private String mSongName;
	private SongState mState;
	private Date mCreationDate;
	private Date mLastUpdateDate;
	
	/** Preferred url for this song**/
	private Url mPreferredUrl;
	
	/** Member specific url **/
	private Url mUrl;
	
	/** A map of all urls for this song with url id **/
	private Map<Long, Url> mUrlsMap;
	
	
	public Song(){
		mUrlsMap = new HashMap<Long, Url>();
	}
	/**
	 * @return the songId
	 */
	public Long getSongId() {
		return mSongId;
	}
	/**
	 * @param pSongId the songId to set
	 */
	public void setSongId(Long pSongId) {
		mSongId = pSongId;
	}
	/**
	 * @return the ownerId
	 */
	public Long getOwnerId() {
		return mOwnerId;
	}
	/**
	 * @param pOwnerId the ownerId to set
	 */
	public void setOwnerId(Long pOwnerId) {
		mOwnerId = pOwnerId;
	}
	/**
	 * @return the songName
	 */
	public String getSongName() {
		return mSongName;
	}
	/**
	 * @param pSongName the songName to set
	 */
	public void setSongName(String pSongName) {
		mSongName = pSongName;
	}
	/**
	 * @return the state
	 */
	public SongState getState() {
		return mState;
	}
	/**
	 * @param pState the state to set
	 */
	public void setState(SongState pState) {
		mState = pState;
	}
	/**
	 * @return the creationDate
	 */
	public Date getCreationDate() {
		return mCreationDate;
	}
	/**
	 * @param pCreationDate the creationDate to set
	 */
	public void setCreationDate(Date pCreationDate) {
		mCreationDate = pCreationDate;
	}
	/**
	 * @return the lastUpdateDate
	 */
	public Date getLastUpdateDate() {
		return mLastUpdateDate;
	}
	/**
	 * @param pLastUpdateDate the lastUpdateDate to set
	 */
	public void setLastUpdateDate(Date pLastUpdateDate) {
		mLastUpdateDate = pLastUpdateDate;
	}
	/**
	 * @return the preferredUrl
	 */
	public Url getPreferredUrl() {
		return mPreferredUrl;
	}
	/**
	 * @param pPreferredUrl the preferredUrl to set
	 */
	public void setPreferredUrl(Url pPreferredUrl) {
		mPreferredUrl = pPreferredUrl;
	}
	/**
	 * @return the url
	 */
	public Url getUrl() {
		return mUrl;
	}
	/**
	 * @param pUrl the url to set
	 */
	public void setUrl(Url pUrl) {
		mUrl = pUrl;
	}
	/**
	 * @return the urlsMap
	 */
	public Map<Long, Url> getUrlsMap() {
		return mUrlsMap;
	}
	/**
	 * @param pUrlsMap the urlsMap to set
	 */
	public void setUrlsMap(Map<Long, Url> pUrlsMap) {
		mUrlsMap = pUrlsMap;
	}
	
	public Collection<Url> getAllUrls(){
		if(getUrlsMap() != null){
			return getUrlsMap().values();
		}
		//return empty array.
		return new ArrayList<Url>();
	}
	
	public Collection<Long> getAllUrlIds(){
		if(getUrlsMap() != null){
			return getUrlsMap().keySet();
		}
		//return empty array
		return new HashSet<Long>();
	}
	
	public void addUrl(Url pUrl){
		if(getUrlsMap() == null){
			setUrlsMap(new HashMap<Long, Url>());
		}
		getUrlsMap().put(pUrl.getUrlId(),pUrl);
	}
}
